<template>
  <div class="app-container">
    <!-- 显示数据 -->
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="24" :lg="8">
        <el-form :model="data" label-position="right" label-width="80px" class="display-form">
          <el-form-item label="员工">
            <el-input v-model="data.employee" disabled></el-input>
          </el-form-item>
          <el-form-item label="时间">
            <el-input v-model="data.time" disabled></el-input>
          </el-form-item>
          <el-form-item label="数量">
            <el-input v-model="data.num" disabled></el-input>
          </el-form-item>
          <el-form-item label="类型">
            <el-input v-model="data.type" disabled></el-input>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getPlan } from '@/api/dayOrder';

export default {
  data() {
    return {
      data: {
        name: this.$route.params.name || '',
        employee: '',
        time: '',
        num: '',
        type: ''
      }
    }
  },
  watch: {
    '$route.params.name': function(newName) {
      this.data.name = newName;
      this.fetchPlanData(newName);
    }
  },
  mounted() {
    this.fetchPlanData(this.$route.params.name);
  },
  methods: {
    fetchPlanData(name) {
      getPlan(name) // 使用getPlan方法获取数据
        .then(response => {
          // 更新响应式数据
          this.data = response.data.data;
        })
        .catch(error => {
          console.error('请求错误:', error);
        });
    }
  }
};
</script>

<style scoped>
.display-form {
  margin-top: 20px;
}

/* 适配小屏幕设备 */
@media (max-width: 767px) {
  .display-form {
    .el-form-item {
      label {
        display: block;
        margin-bottom: 5px;
      }
    }

    .el-input {
      width: 100%;
    }
  }
}
</style>